package rendava;
import java.util.ArrayList;
/**
 * Tag. where each tag is created, the parent, child and sibling of a tag can be returned.  
 * @author 
 * @version 1.2
 */

public abstract class Tag 
{
	private Tag tagType;
	private ArrayList<Tag> children;
	
	/**
	 * Creates tag and a new arrayLisst to hold the children of a tag. 
	 *  
	 */
	public Tag()
	{
		children = new ArrayList<Tag>();
		
	}
	
	/**
	 * Sets the parent tag of a tag
	 * @param par holds the parent if a tag
	 * 
	 */
	public void setparent(Tag par)
	{
		tagType = par; // puts the parent of a tag inside tagType
	}
	
	/**
	 * Sets the child of a tag
	 * @param child holds the child of a tag
	 * 
	 */
	public void setChild(Tag child)
	{
		children.add(child);
	}
	
	
	/**
	 * returns the parent of a tag
	 * 
	 * @return parent tag
	 */
	public Tag getparent()
	{
		return tagType;
	}
	
	/**
	 * returns the first child of a tag 
	 * @return child of tag
	 * 
	 */
	public Tag getchild()
	{
		if (!children.isEmpty())
		{
			return children.get(0);
		}
		else return null;
		
		
	}
	
	/**
	 * returns sibling of tag passed in which is the tag to the right in the array
	 * @param pretag holds the parent of tag
	 * @return sibling of a tag
	 */
	public Tag getSibling(Tag pretag )
	{
		int in = children.indexOf(pretag); // finds the position of pretag in array
		
		
		if (children.size() >=  in+2)
		{
		return children.get(in+ 1);
		}
		else return null;
	}
	
	/**
	 * calls the specific task of a tag
	 * @param renderer holds the renderer
	 * 
	 */
	public abstract void renderInfo(Renderer renderer);
	
	/**
	 * Returns the tags close tag string
	 * @return String holds close tag
	 * 
	 */
	public abstract String closeTag();

}
